﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ScarEngine
{
    

    public class PhysRectangle
    {
        /// <summary>
        /// This is the position in the CENTER of the object!
        /// </summary>
        public Vector2 Position;
        public float Width;
        public float Height;


        public PhysRectangle(float X, float Y, float width, float height)
        {
            Position = new Vector2(X, Y);
            Width = width;
            Height = height;
        }


        #region Methods

        public static bool Intersecting(PhysRectangle A, PhysRectangle B)
        {

            // Initial Check
            float WidthA = A.Width / 2;
            float WidthB = B.Width / 2;
            float HeightA = A.Height / 2;
            float HeightB = B.Height / 2;

            if (A.Position.X < B.Position.X)
            {
                if (A.Position.X + A.Parag(WidthA, HeightA) > B.Position.X - B.Parag(WidthB, HeightB))
                {
                    if (A.Position.X + WidthA > B.Position.X - WidthB)
                    {
                        if (A.Position.Y < B.Position.Y)
                        {
                            if (A.Position.Y + HeightA > B.Position.Y - HeightB)
                            {
                                return true;
                            }
                            else
                            {
                                return false;
                            }

                        }

                        else

                            if (A.Position.Y > B.Position.Y)
                            {
                                if (B.Position.Y + HeightB > A.Position.Y + HeightA)
                                {
                                    return true;
                                }
                                else
                                {
                                    return false;
                                }

                            }

                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            else
            {
                //todo
            }

                //TODO

            return true;

        }

        private float Parag(float A, float B)
        {
            float Ans = (float)Math.Sqrt(Math.Pow((double)A, 2) * Math.Pow((double)B, 2));
            return Ans;
        }

        #endregion
    }

}